<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>角色</title>
    <link rel="stylesheet" href="${ctx}/static/ztree/css/demo.css" type="text/css" />
	<link rel="stylesheet" href="${ctx}/static/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
	<script type="text/javascript" src="${ctx}/static/js/iconselector.js"></script>
    <script type="text/javascript">
    	var viewType = "${viewType}";
    	var zNodes;
		var setting = {
				check: {enable: true,chkStyle: "radio",radioType: "all"},
				view: {selectedMulti: false,dblClickExpand: false},
				data: {simpleData: {enable: true}},
				callback: {onClick: onClick,onCheck: onCheck}
		};
	
		$.ajax({
			   type: "POST",
			   url: "${ctx}/menu/menuJson",
			   cache: true,
			   async:false,
			   dataType:'json',
			   success: function(result){
				   if (typeof(result)== "string") {
					   result = eval("(" + result + ")");
				   }
				   zNodes=result;
			   }
			});
		
        $(function ()
        {
        	
        	$.fn.zTree.init($("#treeDemo"),setting,zNodes);
        	
            mainform=$("#mainform");
            
            mainform.ligerForm();
            
            $("#muIcon").attr("readonly", "readonly");
            $("#parentName").attr("readonly", "readonly");
            
           if(viewType=="modify"){
           	 	$("#muId").attr("readonly", "readonly").removeAttr("validate");
           }
           
           if(viewType=="detail"){
           		$("input,select,textarea",mainform).attr("readonly", "readonly");
           }else{
        	   
	       		$("#parentName").focus(function(event){
	    			showMenu(event);
	    		});
	       		
	       		$("#muIcon").focus(function(){
	       			f_openIconsWin("${ctx}");
	       		});
	       		
               $.metadata.setType("attr", "validate");
               LG.validate(mainform);
           }
            
           LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);
          
        });  
        
        
        function save(){
            LG.submitForm(mainform, function (result) {
            	if(typeof(result)=="string"){
            		result=eval("("+result+")");
            	}
                if (!result.success) {
                    LG.showError('错误:' + data.message);
                }
                else { 
                    LG.showSuccess('保存成功', function () { 
                       LG.callParent("menuList");
                    });
                }
            });
        }
        
        function cancel(){
            var win = window.parent || window;
            if(win.dialog){
            	win.dialog.close();
            }
        }
        
    	function onClick(e, treeId, treeNode) {
    		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
    		zTree.checkNode(treeNode, !treeNode.checked, null, true);
    		return false;
    	}

    	function onCheck(e, treeId, treeNode) {
    		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
    		var nodes = zTree.getCheckedNodes(true);
    		if (nodes.length>0) {
    			$("#parentId").val(nodes[0].id);
    			$("#parentName").val(nodes[0].name);
    		}
    		hideMenu();
    	}

    	function showMenu(event) {
			var obj = $("#parentName");
			var offset = $("#parentName").offset();
			$("#menuContent").css({left:offset.left + "px", top:offset.top + obj.outerHeight() + "px"}).slideDown("fast");
    		$("body").bind("mousedown", onBodyDown);
    	}
    	function hideMenu() {
    		$("#menuContent").fadeOut("fast");
    		$("body").unbind("mousedown", onBodyDown);
    	}
    	function onBodyDown(event) {
    		if (!(event.target.id == "menuBtn" || event.target.id == "parentName" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
    			hideMenu();
    		}
    	}
    </script>
</head>

<body style="padding:10px">
    <form name="mainform" method="post"  id="mainform" action="${ctx }/menu/save">
     <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 100%;">
            <tr>
                <td align="left" class="l-table-edit-td">语言:</td>
                <td align="left" class="l-table-edit-td" style="width:160px" >
                	<select name="langType" id="langType" ltype="select">
								<c:forEach items="${langTypes}" var="obj">
									<c:choose>
										<c:when test="${command.langType eq obj.id.tdId}">
											<option value="${obj.id.tdId}" selected="selected">${obj.tdName}</option>
										</c:when>
										<c:otherwise>
											<option value="${obj.id.tdId}">${obj.tdName}</option>
										</c:otherwise>
									</c:choose>
									
								</c:forEach>
					</select>
                </td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top">父层菜单:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
					<input type="hidden" name="parent.muId" id="parentId" value="${command.parent.muId}"/> 
					<input id="parentName" name="parentName" value="${command.parent.muName}" type="text" ltype="text"  validate="{required:true,notnull:true}"/>
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="left" class="l-table-edit-td" valign="top">菜单代码:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input type="text" name="muId" id="muId" value="${command.muId }" ltype="text" validate="{required:true,minlength:3,maxlength:50,notnull:true,remote:'${ctx}/menu/checkMuId?oldMuId=${command.muId}'}"/>
                </td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top">菜单名称:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input type="text" name="muName" id="muName" ltype="text" value="${command.muName}" validate="{required:true}"/>
                </td>
                <td align="left"></td>
            </tr>   
            
            <tr>
                <td align="left" class="l-table-edit-td" valign="top">可否代理:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
							<c:choose>
								<c:when test="${command.isDeputy eq 'T'}">
									<input type="checkbox" name="isDeputy" value="T" onchange="changeTnf(this)" checked="checked"/>
								</c:when>
								<c:otherwise>
									<input type="checkbox" name="isDeputy" value="F" onchange="changeTnf(this)"/>
								</c:otherwise>
							</c:choose>
                </td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top">功能介绍:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input id="muDesc" name="muDesc" value="${command.muDesc}" type="text" ltype="text"/>
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="left" class="l-table-edit-td" valign="top">窗口锚标记:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input type="text" name="muRel" id="muRel" value="${command.muRel}" ltype="text" validate="{required:true,minlength:1,maxlength:50,notnull:true}"/>
                </td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top">链接地址:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input type="text" name="muHref" id="muHref" value="${command.muHref }" ltype="text" validate="{required:true,minlength:5,maxlength:50,notnull:true,remote:'${ctx}/menu/checkMuHref?oldMuHref=${command.muHref }'}"/>
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="left" class="l-table-edit-td" valign="top">排序:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                	<input type="text" name="muOrd" id="muOrd" value="${command.muOrd}" ltype="text" validate="{required:true,digits:true,notnull:true}"/>
                </td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top"></td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="left" class="l-table-edit-td" valign="top">图标:</td>
                <td align="left" class="l-table-edit-td" style="width:160px" colspan="4">
                	<input type="text" name="muIcon" id="muIcon" value="${command.muIcon}" ltype="text" validate="{required:true,notnull:true}"/>
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="left" class="l-table-edit-td">备注:</td>
                <td align="left" class="l-table-edit-td"> 
                <textarea cols="100" rows="3" class="l-textarea" id="remark" name="remark" style="width:400px">${command.remark}</textarea>
                </td> <td align="left"></td>
           </tr>
           <tr>
                <td align="left" class="l-table-edit-td" valign="top">建档人:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">${command.userCre}</td>
                <td align="left"></td>
                
                <td align="left" class="l-table-edit-td" valign="top">修改人:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">${command.userUpd}</td>
                <td align="left"></td>
           </tr>
        </table>
    </form>
    
	<div id="menuContent" class="menuContent"
		style="display: none; position: absolute;">
		<ul id="treeDemo" class="ztree" style="margin-top: 0; width: 170px; height: 300px;"></ul>
	</div>

</body>
</html>
